/**
 * Created by lvlq on 16/3/15.
 */
var img_src = "/home/image/";
var imgList = [
    "bg.jpg",
    "bg-mo.png",
    "buycart-l.png",
    "buycart-r.png",
    "cloud-l.png",
    "cloud-r.png",
    "green-house.png",
    "red-house.png",
    "person.png"
];

var loadImg = function (src, cb) {
    var img = new Image();
    img.src = src;
    img.onload = img.onerror = function () {
        cb && cb();
    }
};

var load = function (index, cb) {
    if (index >= imgList.length) {
        cb && cb();
        return;
    }

    var src = img_src + imgList[index];

    loadImg(src, function () {
        var percent = Math.floor(index / imgList.length * 100);
        $("#loading .word span").html(percent);
        var move = 5.09333 * percent / 100;
        $("#loading .cart").css({
            'transform': 'translateX(' + move + 'rem)',
            '-webkit-transform': 'translateX(' + move + 'rem)'
        });

        index++;
        load(index, cb);
    });
};

load(0, function () {
    $("#loading").fadeOut();
    $(".container").show();
});